//
//  SPBaseController.swift
//  SparklingPets
//
//  Created by iOS-Czz on 2023/10/26.
//

import UIKit
class SPBaseController: UIViewController {
    lazy var rightButton: UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(clockRightBarButtonAction), for: .touchUpInside)
        return button
    }()
    lazy var leftButton: UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(clockLeftBarButtonAction), for: .touchUpInside)
        return button
    }()
    typealias PageAppearNavigationBarHandler = (_ animated: Bool) -> Void
    
    var handler: PageAppearNavigationBarHandler?
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        if let handler = handler {
            handler(animated)
        } else {
            navigationController?.setNavigationBarHidden(true, animated: animated)
        }
    }
    override var preferredStatusBarStyle: UIStatusBarStyle {
        if #available(iOS 13.0, *) {
            return .default
        } else {
            return .default
            // Fallback on earlier versions
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = VIEW_BG_COLOR

        // Do any additional setup after loading the view.
    }
    override var wx_titleTextAttributes: [NSAttributedString.Key : Any]?{
        return [.foregroundColor: NAV_TITLE_COLOR]
    }
    func addRightBarButton(imageName:String){
        self.rightButton.setImage(UIImage(named: imageName), for: .normal)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: self.rightButton)
    }
    func addRightBarButton(title:String,color:UIColor){
        self.rightButton.setTitle(title, for: .normal)
        self.rightButton.setTitleColor(color, for: .normal)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: self.rightButton)
    }
    
    func addLeftBarButton(imageName:String){
        self.leftButton.setImage(UIImage(named: imageName), for: .normal)
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: self.leftButton)
    }
    func addLeftBarButton(title:String,color:UIColor){
        self.leftButton.setTitle(title, for: .normal)
        self.leftButton.setTitleColor(color, for: .normal)
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: self.leftButton)
    }
    @objc func clockRightBarButtonAction(){
        
    }
    @objc func clockLeftBarButtonAction(){
        self.navigationController?.popViewController(animated: true)
    }
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
